package cn.tedu.luban.worker.main.repository;

import cn.tedu.luban.worker.main.converter.WorkerCategoryConverter;
import cn.tedu.luban.worker.main.mapper.WorkerCategoryMapper;
import cn.tedu.luban.worker.protocol.bo.WorkerCategoryBO;
import cn.tedu.luban.worker.protocol.dos.WorkerAreaDO;
import cn.tedu.luban.worker.protocol.dos.WorkerCategoryDO;
import cn.tedu.luban.worker.protocol.param.WorkerRegistAreaParam;
import cn.tedu.luban.worker.protocol.param.WorkerRegistCategoryParam;
import cn.tedu.luban.worker.protocol.param.WorkerRegistParam;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

@Repository
public class WorkerCategoryRepository {

    @Autowired
    private WorkerCategoryMapper workerCategoryMapper;

    @Autowired
    private WorkerCategoryConverter workerCategoryConverter;

    public void deleteByUserId(Long userId) {
        workerCategoryMapper.deleteByUserId(userId);
    }

    public void saveWorkerCategories(WorkerRegistParam workerRegistParam) {
        //获取师傅的服务品类
        List<WorkerRegistCategoryParam> workerRegistCategoryParams = workerRegistParam.getWorkerRegistCategoryParams();
        //将params 转换成 dos
        List<WorkerCategoryDO> workerCategoryDOS=workerCategoryConverter.params2dos(workerRegistCategoryParams,workerRegistParam.getUserId());
        workerCategoryMapper.batchInsert(workerCategoryDOS);

    }

    public List<WorkerCategoryBO> getCategoriesByUserId(Long userId) {
        List<WorkerCategoryDO> dos=workerCategoryMapper.selectByUserId(userId);
        return workerCategoryConverter.dos2bos(dos);
    }
}
